<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "article".
 *
 * @property integer $id
 * @property string $pubtime
 * @property string $title
 * @property string $content
 * @property string $origin
 * @property integer $clicked
 * @property integer $like
 * @property integer $status
 * @property integer $commentary
 *
 * @property category[] $categories
 * @property articleKeyword[] $articleKeywords
 */
class Article extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'article';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['pubtime'], 'safe'],
            [['title', 'content', 'origin', 'clicked', 'like', 'status', 'commentary'], 'required'],
            [['content'], 'string'],
            [['clicked', 'like', 'status', 'commentary'], 'integer'],
            [['title', 'origin'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'pubtime' => 'Pubtime',
            'title' => 'Title',
            'content' => 'Content',
            'origin' => 'Origin',
            'clicked' => 'Clicked',
            'like' => 'Like',
            'status' => 'Status',
            'commentary' => 'Commentary',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getComments()
    {
        return $this->hasMany(Comment::className(), ['aid' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCategories()
    {
        return $this->hasMany(category::className(), ['id' => 'cid'])
            ->viaTable('article_category', ['aid' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getArticleKeywords()
    {
        return $this->hasMany(Articlekeyword::className(), ['kid' => 'id']);
    }
}
